package cn.swenty.backstage.framework.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.swenty.backstage.framework.database.entity.Entity;
import cn.swenty.backstage.framework.service.CommonService;

@Controller
@RequestMapping("/common/")
public class CommonController extends BasicController{
	
@Autowired
private	CommonService commService;


	@ResponseBody
	@RequestMapping("likeFind")
	public List<Entity> likeFind(){
		
		String  value = getPara("value_");
		String  className = getPara("className");
		String fields = getPara("fields");
		int  limit = 10;
		try{
			limit = Integer.parseInt(getPara("limit"));
		 }catch(Exception e){
			
		}
		return (List<Entity>) commService.likeFind(className, value,fields, limit);
		
	}

	@ResponseBody
	@RequestMapping("isExist")
	public Boolean isExist(){
		
		String  className = getPara("className");
		String field = getPara("field");
		String value = getPara("value_");
		return commService.isExist(className, field, value);
		
	}
	
	@ResponseBody
	@RequestMapping("getFiledValue")
	public Object getFiledValue(){
		
		String  className = getPara("className");
		String field = getPara("field");
		String value = getPara("value_");
		String showField = getPara("showField");
		return commService.getFieldValue(className, field, value, showField);
	}
	
	@ResponseBody
	@RequestMapping("queryList")
	public List<Entity> queryList(){
		String  className = getPara("className");
		String key = getPara("key");
		String value = getPara("value");
		return commService.queryList(className, key, value);
	}
	
}
